#pragma once

#include<iostream>
#include<string>
#include<cstdio>
#include<functional>
#include<pthread.h>

//typedef std::function<void*(void*)> fun_c;
typedef void*(*fun_c)(void*);

class threadData
{
public:
    void*args;
    std::string name;
};

class thread
{
public:
    thread(int num,fun_c funt,void*args)
    :funt_(funt)
    ,num_(num)
    {
        char namebuffer[1024];
        snprintf(namebuffer,sizeof namebuffer,"thread [%d]",num_);
        name_=namebuffer;

        data_.args=args;
        data_.name=name_;
    }

    void start()
    {
        pthread_create(&tid,nullptr,funt_,(void*)&data_);
    }

    void join()
    {
        pthread_join(tid,nullptr);
    }

    std::string name()
    {
        return name_;
    }

    ~thread()
    {}

private:
    pthread_t tid;
    int num_;
    threadData data_;
    std::string name_;
    fun_c funt_;
};